/**
 * 
 */
package br.embedded.socialapp.business;

import java.util.List;

import br.embedded.socialapp.data.DataFacade;
import br.embedded.socialapp.domain.Usuario;
import br.embedded.socialapp.exceptions.UserException;

/**
 * @author daniel
 *
 */
public class UserManager
{
	private static UserManager singleton;
	private static DataFacade facade;
	
	private UserManager()
	{
		facade = DataFacade.getInstance();
	}
	
	public static UserManager getInstance()
	{
		if (singleton == null)
			singleton = new UserManager();
		return singleton;
	}
	
	public void createUser(String login, String firstName, String lastName, String passwd) throws UserException
	{
		if (facade.checkLogin(login) == false)
			facade.createUser(login, firstName, lastName, passwd);
		else
			throw new UserException("Usuário já existente");
	}
	
	public void updateSocialNetworkId(String login, String socialNetwork, String id) throws UserException
	{
		if (facade.checkLogin(login))
			facade.updateSocialNetworkId(login, socialNetwork, id);
		else
			throw new UserException("Usuário não existente");
	}
	
	public Usuario getUserByLogin(String login) throws UserException
	{
		Usuario usuario = facade.getUserByLogin(login);
		
		if (usuario != null)
			return usuario;
		else
			throw new UserException("Usuário não existente");
	}
	
	public List<Usuario> getUserById(String id)
	{
		return facade.getUserById(id);
	}
	
	public boolean doLogin(String login, String passwd)
	{
		return facade.doLogin(login, passwd);
	}
}
